#include "group.hpp"
#include <imgui.h>
#include "content/data_provider.hpp"
#include "core/assert.hpp"
#include "ui/container/container_base.hpp"

void group::init_content(const xml_node &node) {
    ui_container::init_content(node);
    header_ = create_data(node.attribute("header").as_string(), std_string|c_string);
    PI_ASSERT_MSG(header_, "group missing header attribute!");
}

void group::draw_self ()
{
    std::string header_text = header_->get_std_string();
    is_open_ = ImGui::TreeNodeEx(header_text.c_str(), ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_DefaultOpen);
    if (is_open_)
        ImGui::TreePush(this);
}

void group::draw_children ()
{
    if (is_open_) {
        ImGui::AlignTextToFramePadding();
        for (auto &x: children_)
            x->draw();
        ImGui::TreePop();
    }
}
